package com.yunxin.customui.bean.echart;

import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Data
public class Axis implements Serializable {

    /**
     * 轴的名字
     */
    String name;
    /**
     * 类型
     */
    String type;

    boolean boundaryGap = false;
    /**
     * 数据
     *///    String[] data = new String[]{"0"};
    List<String> data;
    /**
     * 最大值
     */
    Double max ;
    /**
     * 最小值
     */
    Double min ;

    /**
     * 轴标签对象
     */
    AxisLabel axisLabel = new AxisLabel();

    SplitLine splitLine = new SplitLine();

    @Data
    static class AxisLabel{
        int interval = 0;
    }

    private Axis(){

    }

    /**
     * 得到x轴
     *
     * @param config 配置
     * @param data   数据
     */
    public static List<com.yunxin.customui.bean.echart.Axis> getXAxis(ChartCfgBean config , List<String> data){
        com.yunxin.customui.bean.echart.Axis xAxis = new com.yunxin.customui.bean.echart.Axis();
        xAxis.axisLabel.interval = config.xInterval;
        xAxis.type = "category";
        xAxis.name = config.xName;
        xAxis.data = data;
        xAxis.splitLine.show = false;
        return Collections.singletonList(xAxis);
    }

    /**
     * 生成y轴
     *
     * @param config 配置
     */
    public static List<com.yunxin.customui.bean.echart.Axis> getYAxis(ChartCfgBean config){
        List<com.yunxin.customui.bean.echart.Axis> yAxisList = new ArrayList<>();
        if (config.getYLName()!=null && !config.getYLName().isEmpty()){
            com.yunxin.customui.bean.echart.Axis yAxis = new com.yunxin.customui.bean.echart.Axis();
            yAxis.type = "value";
            yAxis.name = config.yLName;
            yAxis.splitLine.show = false;
            yAxisList.add(yAxis);
        }
        if (config.getYRName()!=null && !config.getYRName().isEmpty()){
            com.yunxin.customui.bean.echart.Axis yAxis = new com.yunxin.customui.bean.echart.Axis();
            yAxis.type = "value";
            yAxis.name = config.yRName;
            yAxis.splitLine.show = false;
            yAxisList.add(yAxis);
        }
        return yAxisList;
    }

    @Data
    static class SplitLine{
        boolean show = false;
    }
}
